<?php

/*
 * Класс-обертка над стандартными сессиями
 */

namespace T4;

use T4\Config;

class Session {

	const DEFAULT_HANDLER = 'standard';

	static $handler;

	static protected function getHandler() {

		if (is_null(self::$handler)) {
			$config = Config::getInstance(\ROOT_PATH . '/config/common.yaml');
			$handler = $config->session->handler ? : self::DEFAULT_HANDLER;
			$handlerClass = '\\T4\\SESSION\\' . ucfirst($handler) . 'Handler';
			self::$handler = new $handlerClass;
		}

		return self::$handler;
		
	}

	public static function init() {
		$handler = self::getHandler();
		$handler->init();
	}

	public static function set($name, $value) {
		$handler = self::getHandler();
		$handler->set($name, $value);
	}

	public static function get($name) {
		$handler = self::getHandler();
		return $handler->get($name);
	}

	public function delete($name) {
		$handler = self::getHandler();
		$handler->delete($name);
	}

}